package org.carabiner.infinitest;

import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.MutableTreeNode;

class TreeModelExpansionListener implements TreeModelListener
{
  private JTree tree;

  public TreeModelExpansionListener(JTree testTree)
  {
    tree = testTree;
  }

  public void treeNodesChanged(TreeModelEvent e)
  {    
    processEvent(e);
  }

  public void treeNodesInserted(TreeModelEvent e)
  {
    processEvent(e);    
  }

  public void treeNodesRemoved(TreeModelEvent e)
  {
    processEvent(e);
  }

  public void treeStructureChanged(TreeModelEvent e)
  {
    //processEvent(e);
  }

  private void processEvent(TreeModelEvent e)
  {      
    if (!SwingUtilities.isEventDispatchThread())
      throw new IllegalStateException("Tree modifications must be done on the event queue");
    tree.expandPath(e.getTreePath());        
//
//    Dimension size = new Dimension(480, 250);
//    tree.getParent().setPreferredSize(size);
//    tree.getParent().invalidate();  
  }
}
